package com.dao;

import com.helper.DBHelper;
import com.model.DiscussScore;
import java.util.List;
import java.util.Map;

public class DiscussScoreDao {

	private DiscussScore toDiscussScore(Map<String, Object> data)
	{
		DiscussScore d = new DiscussScore();
		d.setId((Integer)data.get("id"));
		d.setEexamId((Integer)data.get("exam_id"));
		d.setQueId((Integer)data.get("que_id"));
		d.setUserId((Integer)data.get("user_id"));
		d.setScore((Integer)data.get("score"));
		return d;
	}

	public DiscussScore getById(int id) {
		DiscussScore result = new DiscussScore();
		String sql = "select * from discuss_score where id=" + id;
		DBHelper db = new DBHelper();
		List<Map<String, Object>> data = db.query(sql, null);
		for(Map<String, Object> ele : data) {
			result = toDiscussScore(ele);
		}
		return result;
	}

	public boolean add(int uid,int eid, int qid, int score) {
		String sql = "INSERT INTO `discuss_score` (`user_id`, `exam_id`, `que_id`, `score`) VALUES ("+uid+", "+eid+", "+qid+", "+score+")";
		DBHelper db = new DBHelper();
		return db.update(sql, null);
	}
}
